
open Ocamlbuild_plugin
open Command

let home = Sys.getenv "HOME"
let seanlib_dir   = home ^ "/save/versioned/projects/kepler/code/ocaml-lib/_build"

let have_cfsqp = "-DHAVE_CFSQP"
let cfsqp_lib = "-lcfsqp"
let cfsqp_libdir  = "-L/usr/local/cfsqp"
let cfsqp_include = "-I/usr/local/cfsqp"

let static = false

let headers = ["cfsqpusr.h"]

;;

dispatch begin function
| After_rules ->

    flag ["ocamlmklib"; "c"]
      (S[A cfsqp_libdir; A cfsqp_lib]);

    flag ["c"; "compile"; "include_cfsqp"]
         (S[A"-ccopt"; A cfsqp_include; A"-ccopt"; A have_cfsqp]);

    flag ["link"; "ocaml"; "library"; "use_cfsqp"]
         (S[A"-ccopt"; A cfsqp_libdir; A"-cclib"; A cfsqp_lib]);

    if static then flag ["link"; "ocaml"; "byte"] (A"-custom");

    ocaml_lib "mlfsqp";

    flag ["link"; "library"; "ocaml"; "byte"; "use_libcfsqp"]
         (S[A"-dllib"; A cfsqp_lib; A"-cclib"; A cfsqp_lib]);

    flag ["link"; "library"; "ocaml"; "native"; "use_libcfsqp"]
         (S[A"-cclib"; A cfsqp_lib]);

    flag ["link"; "native"; "use_mlfsqp"]
      (S[A"-ccopt"; A"-L."]);

    flag ["link"; "byte"; "use_mlfsqp"]
      (S[A"-dllpath"; A"."]);

    (* -------------------------------  Seanlib  -------------------------------- *)
        
    flag ["compile"; "ocaml"; "use_seanlib"]
         (S[A"-I"; A seanlib_dir]);

    flag ["link"; "ocaml"; "byte"; "program"; "use_seanlib"]
         (S[A"-I"; A seanlib_dir; A"lib.cma"]);

    flag ["link"; "ocaml"; "native"; "program"; "use_seanlib"]
         (S[A"-I"; A seanlib_dir; A"lib.cmxa"]);


| _ -> ()
end
